<?php
/**
 * Trieda sablony
 * @author Tomas Srna
 * @package bakalarka
 */
class Template extends Singleton
{
	/**
	 * Hooky pre pridanie obsahu do inak nepristupnych casti stranky
	 * @var array $hook
	 */
	protected $hook = array('headBegin' => '', 
		'headEnd' => '', 'bodyBegin' => '', 'bodyEnd' => '');
	
	/**
	 * Pridanie hooku
	 * @param string $hookName		Nazov hooku
	 * @param string $content		Vkladany obsah hooku
	 * @return void
	 */
	function addHook($hookName, $content)
	{
		if(	$hookName != 'headBegin' && 
			$hookName != 'headEnd' && 
			$hookName != 'bodyBegin' && 
			$hookName != 'bodyEnd')
			return false;
		$this->hook[$hookName] .= $content;
	}
	
	/**
	 * Vyrenderovanie hooku
	 * @param string $hookName		Nazov hooku
	 * @return void
	 */
	function renderHook($hookName)
	{
		if(	$hookName != 'headBegin' && 
			$hookName != 'headEnd' && 
			$hookName != 'bodyBegin' && 
			$hookName != 'bodyEnd')
			return false;
		echo $this->hook[$hookName];
	}
	
	/**
	 * Vyrenderovanie celeho templatu
	 * @param string $template		Nazov templatu
	 * @return void
	 */
	function render($template = 'default')
	{
		if(!file_exists(APPROOT.'template'.DS.$template.'.phtml'))
			throw new Exception('L::templateNotFound');
		else
			include APPROOT.'template'.DS.$template.'.phtml';
	}
}